//
//  UIButton+AsyncImage.m
//  ZJWR
//
//  Created by 付卫涛 on 14-9-17.
//  Copyright (c) 2014年 3TI. All rights reserved.
//

#import "UIButton+AsyncImage.h"

@implementation UIButton (AsyncImage)


- (void)setImageFromURL:(NSString *)urlString
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        UIImage *image = nil;
        NSURL *url = [NSURL URLWithString:urlString];
        NSData *data = [NSData dataWithContentsOfURL:url];
        image = [UIImage imageWithData:data];
        
        if (image) {
        
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self setBackgroundImage:image forState:UIControlStateNormal];

            });
        }
        else {
            NSLog(@"async load error.");
        }
    });
}
@end
